// pages/list/list.js

Page({

  /**
   * 页面的初始数据
   */
  data: {
    cartList: [],
    sumMoney: 0,
    orderNumber: 0,
    list: [],
    userInfo:[],
    avatarUrl:'',
    nickName:'',

  },
  list:function(){
    var that = this;
    var arr = new Array();
    for(var index in that.data.cartList){
      var obj={
      id: that.data.cartList[index].id,
      num: that.data.cartList[index].number,
      price: that.data.cartList[index].price,
      money: that.data.cartList[index].sum,
      state: 0,
      }
      arr.push(obj);
    }
    that.setData({
      list:arr,
    })
    console.info(that.list),
    console.log(that.list)
    
},
  /*跳转至支付页面*/
  payforit:function(){
    this.list();
    wx.setStorageSync('list', this.data.list);  //订单列表
    wx.setStorageSync('cartList', this.data.cartList);  //购物车列表
    wx.setStorageSync('sumMoney', this.data.sumMoney);  //价格
    wx.setStorageSync('orderNumber', this.data.orderNumber);   //数量
    wx.navigateTo({
      url: '../confirm/confirm'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var that = this;
    var arr = new Array();
    var userInfo =wx.getStorageSync('userInfo');

      //设置data
      // let info = e.detail.userInfo;
      this.setData({
        cartList: wx.getStorageSync('cartList'),
        sumMoney: wx.getStorageSync('sumMoney'),
        orderNumber: wx.getStorageSync('orderNumber'),
        userInfo:userInfo,
        // avatarUrl:info.avatarUrl,
        // nickName:info.nickName,
      })

    for(var index in that.data.cartList){
      var obj={
      id: that.data.cartList[index].id,
      num: that.data.cartList[index].number,
      price: that.data.cartList[index].price,
      money: that.data.cartList[index].sum,
      state: 0,
      }
      arr.push(obj);
    }
    that.setData({
      list:arr,
    })


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})